var api = require("../../api.js"), app = getApp();
var images = require('../../utils/images.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    page_count:0,
    row_count:0,
    bindShow:"none",
    noInput:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(1);
    app.pageOnLoad(this);
    var t = this;
    wx.showLoading({
      title: "加载中"
    }), app.request({
      url: api.user.level_cart,
      success: function (e) {
        var a = e.data;
        console.log(e.data);
        t.setData(e.data);
      },
      complete: function (e) {
        wx.hideLoading();
      }


    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady:function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  upMember:function(){

    app.request({
      url: api.user.up_member,
      method:"POST",
      data:{type:"2"},
      success: function (e) {
        var a = e.data;
        console.log(e);
        wx.requestPayment({
          'timeStamp': a.timeStamp.toString(),
          'nonceStr': a.nonceStr,
          'package': a.package,
          'signType': a.signType,
          'paySign': a.paySign,
          'success': function (res) {
            console.log('支付成功');
          },
          'fail': function (res) {
            console.log('支付失败');
            return;
          },
          'complete': function (res) {
            console.log('支付完成');
            var url = "/share-gold/share-gold";
            console.log('get url', url)
            if (res.errMsg == 'requestPayment:ok') {
              wx.showModal({
                title: '提示',
                content: '支付成功'
              });
              if (url) {
                setTimeout(function () {
                  wx.redirectTo({
                    url: '/pages' + url
                  });
                }, 2000)
              } else {
                setTimeout(() => {
                  wx.navigateBack()
                }, 2000)
              }
            }
            return;
          }
        });
        
      }});
  },
  upMember2: function () {
    
    app.request({
      url: api.user.up_member,
      method: "POST",
      data: { type: "3" },
      success: function (e) {
        var a = e.data;
        console.log(e);

        wx.requestPayment({
          'timeStamp': a.timeStamp.toString(),
          'nonceStr': a.nonceStr,
          'package': a.package,
          'signType': a.signType,
          'paySign': a.paySign,
          'success': function (res) {
            console.log('支付成功');
          },
          'fail': function (res) {
            console.log('支付失败');
            return;
          },
          'complete': function (res) {
            console.log('支付完成');
            var url = "/share-gold/share-gold";
            console.log('get url', url)
            if (res.errMsg == 'requestPayment:ok') {
              wx.showModal({
                title: '提示',
                content: '支付成功'
              });
              if (url) {
                setTimeout(function () {
                  wx.redirectTo({
                    url: '/pages' + url
                  });
                }, 2000)
              } else {
                setTimeout(() => {
                  wx.navigateBack()
                }, 2000)
              }
            }
            return;
          }
        });

      }
    });
  },
  showBindCard:function(){
     var display =  this.data.bindShow;
     console.log(display);
     if(display=="none"){
       this.setData({"bindShow":""});
     }else{
       this.setData({"bindShow": "none" });
     }
  },
  bindCard:function(){
    var no = this.data.noInput;
   // var user_id = "226";
    console.log(no);
    if(no.trim()==''){
   
      wx.showModal({
        title: '温馨提示',
        content: '绑定的卡号不能为空',
      })
    }else{
      wx.showModal({
        title: '温馨提示',
        content: '确认绑定卡'+no+"吗？",
        success:function(){
          app.request({
            url: api.user.level_card_check,
            method: "POST",
            data: { no: no},
            success: function (e) {
              var a = e;
              console.log(e);
              wx.showToast({
                title: e.msg,
                icon:"none"
              })
              var url = "/share-gold/share-gold";
              setTimeout(function () {
                wx.redirectTo({
                  url: '/pages' + url
                });
              }, 2000)
              if(e.code==1){
                
              }

            }
          });
        }
      })
    }

    
  },
  noInput:function(e){
      this.setData({"noInput":e.detail.value});
  }
})
